// Copyright (c) 2020 Presto Labs Pte. Ltd.
// Author: xguo

#pragma once

#include <vector>

#include "coin2/exchange/base/order/processor.h"

class CancelAllExecutor {
 public:
  using exchange::base::order::IOrderSubsystem;

 public:
  CancelAllExecutor() { }
  ~CancelAllExecutor() { }

  AddOrderSubsystem(IOrderSubsystem* os) {
    os_list_.push_back(os);
  }

  bool CancelAll() {
    bool finished = true;
    for (auto os : os_list_) {
      auto og = os->order_gateway();
      if (og->order_manager().GetWorkingOrderCount() > 0) {
        og.CancelAll();
        finished = false;
      }
    }
    return finished;
  }

 private:
  std::vector<IOrderSubsystem*> os_list_;
};
